package fakedata

import (
	"doctor_api_backend/config"
	"doctor_api_backend/models"
	"fmt"
	"math/rand"
	"time"

	"github.com/google/uuid"
)

// 生成唯一的病历记录号
func generateUniqueMedicineRecordNumber() string {
	return uuid.New().String() // 使用 UUID 生成唯一的病历记录号
}

// 生成随机日期
func generateRandomDateForMedicalRecord() time.Time {
	year := rand.Intn(5) + 2021 // 生成未来 5 年内的日期
	month := time.Month(rand.Intn(12) + 1)
	day := rand.Intn(28) + 1
	return time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
}

// 生成假数据
func SeedMedicineRecordData() {
	chiefComplaints := []string{"头痛", "发热", "咳嗽", "腹痛", "乏力"}
	diagnoses := []string{"感冒", "流感", "肺炎", "肠胃炎", "贫血"}
	treatmentPlans := []string{"休息", "多喝水", "药物治疗", "物理降温"}
	medications := []string{"阿莫西林", "布洛芬", "对乙酰氨基酚", "维生素C"}
	statuses := []string{"已完成", "进行中", "待处理"}

	for i := 0; i < 100; i++ {
		record := models.MedicalRecord{
			MedicalRecordCode:   fmt.Sprintf("M%d", i),
			PatientID:           uint(rand.Intn(100) + 1),             // 假设患者 ID 是 1 到 100
			DoctorID:            uint(rand.Intn(100) + 1),             // 假设医生 ID 是 1 到 100
			MedicalRecordNumber: generateUniqueMedicineRecordNumber(), // 生成唯一的病历记录号
			ChiefComplaint:      chiefComplaints[rand.Intn(len(chiefComplaints))],
			Diagnosis:           diagnoses[rand.Intn(len(diagnoses))],
			TreatmentPlan:       treatmentPlans[rand.Intn(len(treatmentPlans))],
			Medications:         medications[rand.Intn(len(medications))],
			RecordDate:          generateRandomDateForMedicalRecord(),
			Status:              statuses[rand.Intn(len(statuses))],
		}

		config.DB.Create(&record)
	}

	fmt.Println("100 条假 `病历记录`数据已成功插入数据库")
}
